# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  include LoginEngine
  include UserEngine
  
  
  # Abstraction to make views a little cleaner
  def form_input(helper_method, prompt, field_name=nil, options = {}, form_name = nil)
    form_name = "user" if form_name.nil?
    case helper_method.to_s
    when 'hidden_field'
      self.hidden_field(form_name, field_name, options)
    when /^.*button$/
      #prompt = l(:"#{@controller.controller_name}_#{field_name}_button")
      <<-EOL
      <tr><td class="button" colspan="2">
        #{self.send(helper_method, form_name, prompt, options)}
      </td></tr>
      EOL
    else
      field = (
        case helper_method
        when :select
          self.send(helper_method, form_name, field_name, options.delete('values'), options)
        when :password_field
          options[:value] = ""
          self.send(helper_method, form_name, field_name, options)
        else
          self.send(helper_method, form_name, field_name, options)
        end)
#      lname = "#{form_name}_#{field_name}_form"
#      prompt = l(:"#{lname}")
      if LoginEngine.config(:two_column_input)
<<-EOL
        <tr class="two_columns">
          <td class="prompt" align=right><label>#{prompt}</label></td>
          <td class="value" align=left>#{field}</td>
        </tr>
        EOL
      else
<<-EOL
        <tr><td class="prompt" align=right><label>#{prompt}</label></td></tr>
        <tr><td class="input" align=left>#{field}</td></tr>
        EOL
      end
    end
  end
  
  
end
